<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:dxl="http://www.lotus.com/dxl"
    xmlns:session="java:ro.egmar.dojocache.extensions.SessionExtension"
    exclude-result-prefixes="session xs dxl">
    
    <!-- Output options -->
    <xsl:output
        method="html"
        omit-xml-declaration="yes"
        indent="yes"
    />
    
    <!-- Global parameters -->
    <xsl:param name="webDbPath"/>
    <xsl:param name="notesDbPath"/> 
    <xsl:param name="mode"/>
    <xsl:param name="unid"/>
    
    <!-- Strip whitespace -->
    <xsl:strip-space elements="*"/>
    
    <!-- Overriding default templates -->
    <xsl:template match="text()|@*" />
    
    <!-- Richtext stylesheet -->
    <xsl:include href="data/xsl/richtext.xsl"/>
    
    <!-- Fields stylesheet -->
    <xsl:include href="data/xsl/fields.xsl"/>
        
    <!-- Tempalte for section -->
    <xsl:template match="dxl:section">
    	<div dojoType="TitlePane" label="{dxl:sectiontitle/dxl:text/text()}" open="false">
    		<xsl:apply-templates/>
    	</div>
    </xsl:template>
    
    <!-- Template for tabbed table -->
    <xsl:template match="dxl:table[@rowdisplay='tabs']">
        <div dojoType="TabContainer" style="height:200px;">
            <xsl:apply-templates/>
        </div>
    </xsl:template>
    
    <!-- Template for tabbed table row -->
    <xsl:template match="dxl:table[@rowdisplay='tabs']/dxl:tablerow">
        <div dojoType="ContentPane" label="{@tablabel}">
            <xsl:apply-templates/>    
        </div>
    </xsl:template>
    
    <!-- Template for captions table -->
    <xsl:template match="dxl:table[@rowdisplay='captions']">
        <div dojoType="AccordionContainer" 
            labelNodeClass="label" 
            containerNodeClass="accBody" 
            style="height:200px;">
            <xsl:apply-templates/>
        </div>
    </xsl:template>
    
    <!-- Template for captions table row -->
    <xsl:template match="dxl:table[@rowdisplay='captions']/dxl:tablerow">
        <div dojoType="ContentPane" label="{@tablabel}">
            <xsl:apply-templates/>    
        </div>
    </xsl:template>
    
    <!-- Template for embeddedoutline widget -->
    <xsl:template match="dxl:embeddedoutline">
        <xsl:param name="name"/>
        <div dojoType="DominoOutlinePane"
            categorySymbols="simple"
            orientation="{@display}"
            contentPane="{@targetframe}"
            display="{@type}" 
            outlineName="{@outline}">
        </div>
    </xsl:template>
    
    <!-- Template for subform element -->
    <xsl:template match="dxl:subformref">
        <div dojoType="DominoSubform" subform="{@name}" mode="{$mode}" unid="{$unid}"/>
    </xsl:template>
    
    <!-- Template for embeddedview element -->
    <xsl:template match="dxl:embeddedview">
        <div dojoType="DominoView" 
            view="{@name}" 
            dbReplica="{@database}"/>
    </xsl:template>
    
    <!-- Template for embeddeddatepicker element -->
    <xsl:template match="dxl:embeddeddatepicker">
        <div dojoType="DatePicker"/>
    </xsl:template>
    
    <!-- Template for sharedfield element -->
    <xsl:template match="dxl:sharedfieldref">
        <div dojoType="DominoSharedfield" sharedfield="{@name}"/>
    </xsl:template>
    
    <!-- Template for form element -->
    <xsl:template match="dxl:form">
        <xsl:variable name="repeat">
            <xsl:choose>
                <xsl:when test="child::dxl:background/@repeat='once'">
                    <xsl:value-of select="'no-repeat'"/>
                </xsl:when>
                <xsl:when test="child::dxl:background/@repeat='vrepeat'">
                    <xsl:value-of select="'repeat-y'"/>
                </xsl:when>
                <xsl:when test="child::dxl:background/@repeat='hrepeat'">
                    <xsl:value-of select="'repeat-x'"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="'repeat'"/>
                </xsl:otherwise>
            </xsl:choose>   
        </xsl:variable>
        <div dojoType="ContentPane">
            <xsl:attribute name="style">
                <xsl:text>width:</xsl:text>
                <xsl:value-of select="'100%'"/>
                <xsl:text>;</xsl:text>
                <xsl:text>height:</xsl:text>
                <xsl:value-of select="'100%'"/>
                <xsl:text>;</xsl:text>
                <xsl:text>background:</xsl:text>
                <xsl:value-of select="if (@bgcolor) then @bgcolor else ''"/>
                <xsl:text> </xsl:text>
                <xsl:value-of select="if (child::dxl:background) then concat('url(',codepoints-to-string(39),'/',$notesDbPath,'/',dxl:background/dxl:imageref/@name,codepoints-to-string(39),')',$repeat) else ''"/>
                <xsl:text>;</xsl:text>
            </xsl:attribute>
            <div dojoType="DominoActionbar" basetype="form" baseid="{@name}"/>
            <form name="{@name}" method="post" action="{if ($mode='') then concat($webDbPath,'/',@name,'?OpenForm;seq=1') else concat($webDbPath,'/',$unid,'?SaveDocument;seq=1')}">
                <xsl:apply-templates>
                    <xsl:with-param name="name" select="translate(@name,' ','')" />
                </xsl:apply-templates>
            </form>
        </div>
    </xsl:template>
    
    <!-- Root template, main entry point -->
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>
    
</xsl:stylesheet>